package com.wolfking.converter.service;

import com.wolfking.converter.entity.SqlDefine;
import com.wolfking.converter.entity.SqlDefineParam;
import com.wolfking.converter.entity.SqlFieldTransform;
import com.wolfking.jeesite.mybatis.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

@Slf4j
@Service
public class SqlDefineService extends BaseService<SqlDefine> {

    @Autowired
    private SqlDefineParamService sqlDefineParamService;

    @Autowired
    private SqlFieldTransformService sqlFieldTransformService;

    @Override
    @Transactional
    public List<SqlDefine> deleteById(Serializable id) {
        List<SqlDefine> sqlDefines = super.deleteById(id);
        SqlDefine sqlDefine = sqlDefines.get(0);
        SqlDefineParam sqlDefineParam = new SqlDefineParam();
        sqlDefineParam.setDefineKey(sqlDefine.getDefineKey());
        SqlFieldTransform sqlFieldTransform = new SqlFieldTransform();
        sqlFieldTransform.setDefineKey(sqlDefine.getDefineKey());
        log.info("delete sqlDefineParam size is {},sqlFieldTransform size is {}",
                sqlDefineParamService.deleteExample(sqlDefineParam),
                sqlFieldTransformService.deleteExample(sqlFieldTransform));
        return sqlDefines;
    }
}
